package utils.utils;

import com.alibaba.fastjson.JSONObject;
import utils.utils.vo.InvokerVo;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2018/5/11.
 */
public class TestUtils {
// #selectByPrimaryKey

    public static void main(String[] args) throws Exception {

        Map<String, Object> map = new HashMap<>();
        map.put("insurType", 731);
//        map.put("daysType", 15);
        String beanName = "com.lvmama.vst.back.client.prod.service.ProdProductClientService";
        String methodName = "findInsuranceProductByCondition";
        String result = generation(beanName,methodName,map);
        System.out.println(result);

    }

    public static String generation(String beanName, String methodName, Object... paramsList) {
        InvokerVo invokerVo = new InvokerVo();
        invokerVo.setBeanName(beanName);
        invokerVo.setMethodName(methodName);

        if (paramsList != null) {
            String[] paramsType = new String[paramsList.length];
            String[] params = new String[paramsList.length];
            for (int i = 0; i < paramsList.length; i++) {
                try {
                    paramsType[i] = paramsList[i].getClass().getTypeName();
                    params[i] = JSONObject.toJSONString(paramsList[i]);
                }catch (Exception e){
                    System.err.println("bean name is : " + beanName + " params is :" + paramsType + " index is :" + i);
                    throw new RuntimeException();
                }

            }
            invokerVo.setParamsTypes(paramsType);
            invokerVo.setParams(params);
        }

        return JSONObject.toJSONString(invokerVo);
    }
}
